/*
 * RF12.h
 *
 *  Created on: 23.03.2011
 *      Author: Tavin
 */

#ifndef RF12_H_
#define RF12_H_

#include "RFM12_hw.h"
#include "spi.h"

void RFM12_init(void);
void RFM12_init_RX_interrupt(void);
void RFM12_DauerSender(void);
void RFM12_enableTransmitter(void);
void RFM12_disableAll(void);
void RFM12_enableReceiver(void);

uint8_t RFM12_transmitterModeEnabled;
uint8_t RFM12_receiverModeEnabled;

uint8_t RFM12_testAusgabeDisplay;
uint8_t RFM12_fifoResetPackageCounter;
#define RFM12_FIFORESETAFTERPACKAGES 	0x8 //Einstellung Anzahl Datenbytes pro Durchlauf

void static inline RFM12_sendData(uint16_t data)
{
	spi_selectChip(RFM12_SPI, RFM12_SPI_NPCS);
	spi_write(RFM12_SPI,data);
	spi_unselectChip(RFM12_SPI, RFM12_SPI_NPCS);
}


void static inline RFM12_sendData2(uint16_t data)
{

	uint16_t status;
	status=0;
	while ((status & 0x8000)==0)
	{
	spi_selectChip(RFM12_SPI, RFM12_SPI_NPCS);

	spi_write(RFM12_SPI,RFM12_CMD_STATUS);
	spi_read(RFM12_SPI,&status);

	spi_unselectChip(RFM12_SPI, RFM12_SPI_NPCS);
	}

	spi_selectChip(RFM12_SPI, RFM12_SPI_NPCS);
	spi_write(RFM12_SPI,data);
	spi_unselectChip(RFM12_SPI, RFM12_SPI_NPCS);
}


uint16_t static inline RFM12_readData(uint16_t data)
{
	uint16_t returnValue;

	spi_selectChip(RFM12_SPI, RFM12_SPI_NPCS);

	spi_write(RFM12_SPI,data);
	spi_read(RFM12_SPI,&returnValue);

	spi_unselectChip(RFM12_SPI, RFM12_SPI_NPCS);

	return(returnValue);
}


#endif /* RF12_H_ */



